﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DataAccessLayer;

namespace CommonUtils
{
	public class LogWriter
	{
        /// <summary>     
        /// Add a log entry in the database
        /// </summary>
        public static void AddLog(String logMessage, String logLevel, String applicationName, String functionName)
        {
            try
            {
                LogDAL.AddLog(logMessage, logLevel, applicationName, functionName, System.DateTime.Now);
            }
            catch (Exception e)
            {
                System.Diagnostics.StackFrame sf = new System.Diagnostics.StackFrame();
                LogWriter.AddLog(e, LogStatus.Error, CommonUtilsSettings.Default.ApplicationName, sf.GetMethod().Name);
                throw new Exception(sf.GetMethod().Name + " unexpected error", e);
            }
        }

        /// <summary>     
        /// Add a log entry in the database
        /// </summary>
        public static void AddLog(Exception e, String logLevel, String applicationName, String functionName)
        {
            try
            {
                LogDAL.AddLog(e.Message, logLevel, applicationName, functionName, System.DateTime.Now);
            }
            catch (Exception ee)
            {
                System.Diagnostics.StackFrame sf = new System.Diagnostics.StackFrame();
                LogWriter.AddLog(ee, LogStatus.Error, CommonUtilsSettings.Default.ApplicationName, sf.GetMethod().Name);
                throw new Exception(sf.GetMethod().Name + " unexpected error", ee);
            }
        }
    }

    public class LogStatus
    {
        public static String Error = "Error";
        public static String Critical = "Critical";
        public static String Warning = "Warning";
        public static String Info = "Info";
        public static String Debug = "Debug";
    }
}
